﻿
//将所有方法包入一个对象中
JC.login = {
    GetQueryModel: function () {
        var queryModel = {};
        queryModel.Name = $("#usernameTxt").val();
        queryModel.Pwd = $("#userpwdTxt").val();
        return queryModel;
    },
    //用户登录
    AdminLogin: function () {
        var queryModel = JC.login.GetQueryModel();
        if (queryModel.Name == "" || queryModel.Name == null || queryModel.Pwd == "" || queryModel == null) {
            $(".login .user .fail").show();
            return;
        }
        $.ajax({
            type: "Post",
            url: $("#LoginID").attr("data-url"),
            data: queryModel,
            dataType: "json",
            success: function (data) {
                if (data.code == "1") {
                    window.location.href = data.url;
                }
                else if (data.code=="0") {
                    alert("您的账号已被禁用，请与管理人员联系！")
                }else{
                    $(".login .user .fail").hide();
                    $(".login .password .fail").show();
                }
            },
            error: function () {
                $(".login .user .fail").hide();
                $(".login .password .fail").show();
            }
        });
    },
    //退出登录
    OutLogin: function () {
        $.ajax({
            type: "Post",
            url: $("#outlogin").attr("data-url"),
            data: null,
            dataType: "html",
            success: function (data) {
                window.location.href = "../Management/login/login";
            }
        });
    }
};



//页面加载完成执行
$(function () {
    $("#BtnLogin").click(function () {
        JC.login.AdminLogin();
    });
    $("#outlogin").click(function () {
        JC.login.OutLogin();
    });
    document.onkeydown = function (event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            $("#BtnLogin").click();
        }
    }
})